#!/usr/bin/env bash
# Copyright (c) 2021 The Toltec Contributors
# SPDX-License-Identifier: MIT

pkgnames=(libdlib libdlib-dev)
pkgdesc="Toolkit for making machine learning and data analysis applications in C++"
url=http://dlib.net
pkgver=19.21-2
timestamp=2020-08-08T19:41:07Z
section="devel"
maintainer="Mattéo Delabre <spam@delab.re>"
license=BSL-1.0

image=base:v2.1
source=("https://github.com/davisking/dlib/archive/v${pkgver%-*}.tar.gz")
sha256sums=(116f52e58be04b47dab52057eaad4b5c4d5c3032d927fe23d55b0741fc4107a0)

build() {
    cmake -B build \
        -DCMAKE_TOOLCHAIN_FILE="/usr/share/cmake/$CHOST.cmake" \
        -DCMAKE_INSTALL_PREFIX="/opt" \
        -DBUILD_SHARED_LIBS=ON
    cmake --build build
    cmake --build build --target install -- DESTDIR=../install
}

libdlib() {
    package() {
        install -d "$pkgdir"/opt/lib "$pkgdir"/usr/lib
        cp --no-dereference "$srcdir"/install/opt/lib/lib*.so* "$pkgdir"/opt/lib

        for file in "$pkgdir"/opt/lib/lib*.so*; do
            base="${file#"$pkgdir"}"
            ln -s "$base" "${file/\/opt/\/usr}"
        done
    }
}

libdlib-dev() {
    pkgdesc="$pkgdesc - development files"

    package() {
        install -d "$pkgdir"/opt/lib
        cp -r "$srcdir"/install/opt/lib/pkgconfig "$pkgdir"/opt/lib
        cp -r "$srcdir"/install/opt/lib/cmake "$pkgdir"/opt/lib
        cp -r "$srcdir"/install/opt/include "$pkgdir"/opt
    }
}
